﻿@model CanDichVu.Db.Post
@{
    ViewBag.Title = "Trang đăng tin rao vặt - dịch vụ dành cho thành viên của candichvu.com";
    Layout = "~/Views/Shared/_Layout.cshtml";
    AjaxOptions ajaxOpts = new AjaxOptions
    {
        HttpMethod = "post",
        OnComplete = "completedAjaxRequest"
        //OnBegin = "show_Loading",
    };
}

<div class="page_post_news">

    <div class="page_post_news_left">

        <div class="formdangtin_news">
            @using (Ajax.BeginForm("AddPost", "Post", null, ajaxOpts, new { enctype = "multipart/form-data", name = "frm_register", id = "frm_register" }))
            {
                @Html.HiddenFor(model => model.chuyenmuc, new { id = "ParentIdCode" })
                @Html.HiddenFor(model => model.TinhThanh, new { id = "TinhThanhID" })
                @Html.HiddenFor(model => model.Quanhuyen, new { id = "QuanhuyenID" })
                @Html.HiddenFor(model => model.clat, new { id = "clatId" })
                @Html.HiddenFor(model => model.AnhDaiDien, new { id = "AnhDaiDien" })
                @Html.HiddenFor(model => model.clong, new { id = "clongId" })
                @Html.HiddenFor(model => model.ArrayCate, new { id = "ArrayCate" })
                <h2 class="h2_title_account_login_res">Thông tin đăng rao vặt</h2>
                <div class="clear"></div>
                <div class="warning-area"></div>
                <ul class="form_post_news">
                    <li></li>
                    <li><div class="left">Chuyên mục cần đăng tin</div> <span class="right">
                        <select id="selectCate" class="easyui-combotree" style="width:630px; height:35px;">
                                
                        </select>
                    </span>
                    </li>
                    <li><div class="left">Tiêu đề đăng tin</div> <span class="right">
                        @Html.TextBoxFor(model => model.Title, new { name = "Title", @class = "input_post_news", @placeholder = "Tiêu đề tin", value = "", style = "width: 90%;" })
                    </span>
                    </li>
                    <li><div class="left">Giá tham khảo</div> <span class="right">
                        @Html.TextBoxFor(model => model.Gia, new { name = "Gia",  @class = "input_post_news",  @placeholder = "Giá tham khảo của sản phẩm", value = "", style = "width: 90%;" })
                    </span>
                    </li>
                    <li><div class="left">Hình thức</div> <span class="right">
                        @Html.TextBoxFor(model => model.HinhThuc, new { name = "HinhThuc",  @class = "input_post_news",  @placeholder = "Cần bán hoặc cần mua hoặc sang nhượng ....", value = "", style = "width: 90%;" })
                    </span>
                    </li>
                    <li><div class="left">Ảnh đại diện</div> <span class="right">
                        <div id="event-logo-upload" style="">
                        </div>
                        <div class="bank_hight_5"></div>
                        <button type="button" class="delete ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary button_remove_img" role="button" aria-disabled="false"><span class="ui-button-icon-primary ui-icon ui-icon-trash"></span><span class="ui-button-text">Xóa file</span></button>
                        <img src="@Model.AnhDaiDien" id="imageslogo" width="100" height="100" />
                    </span>
                    </li>
                    <li class="line"><div class="left">Tình trạng sản phẩm</div> <span class="right">
                        @Html.TextBoxFor(model => model.TinhTrang, new { name = "TinhTrang",  @class = "input_post_news",  @placeholder = "Tình trạng của sản phẩm", value = "", style = "width: 90%;" })
                    </span>
                    </li>
                    <li><div class="left">Nội dung chi tiết</div> <span class="right">
                        @Html.TextAreaFor(model => model.Noidung, new { name = "Noidung", rows="25", cols="80", @class="ck_editor_model", @id="ck_editor_model"  })
                    </span>
                    </li>
                    <li></li>
                </ul>
                <h2 class="h2_title_account_login_res">Thông tin vị trí</h2>
                <ul class="form_post_news">
                    <li></li>

                    <li><div class="left">Chọn tỉnh thành</div> <span class="right">
                        <select id="selectCate_tt" class="easyui-combotree" style="width:630px; height:35px;">
                                
                        </select>
                    </span>
                    </li>
                    <li><div class="left">Chọn quận/huyện</div> <span class="right">
                        <select id="selectCate_qh" class="easyui-combotree" style="width:630px; height:35px;">
                               <option>Chọn quyện/huyện</option>
                        </select>
                    </span>
                    </li>
                   <li><div class="left">Thông tin trên bản đồ</div> <span class="right">
                                @Html.TextAreaFor(model => model.Des_on_Maps, new { name = "Des_on_Maps", @class="Des_on_Maps", @id="Des_on_Maps", @style="width: 96%;height:90px" })
                        </span>
                    </li>
                    <li><div class="left">Địa chỉ tìm kiếm <span class="check_qh_tinhthanh"></span></div> <span class="right">
                       <input class="input_post_news" id="diachi_id" name="diachi_id" placeholder="Chỉ nhập số nhà, đường ." style="width: 90%;" type="text" value="">
                    </span>
                    </li>
                    <li>
                        <span>- Bạn có thể nắm giữ hình biểu tượng trên bản đồ để tìm vị trí chính xác</span>
                        <div id="maps_company" style="width:630px; height:350px;">

                        </div>

                    </li>
                    <li class="fone_num">
                        <div class="clear"></div>
                         <div class="right">
                            @Html.Partial("_Captcha", new CanDichVU.Models.Captcha())
                            @Html.Partial("_InvisibleCaptcha", new CanDichVU.Models.InvisibleCaptcha())
                         </div>
                    </li>
                    <li class="line"><span class="left">&nbsp;</span> <span class="right">
                        <input type="submit" style="border: 0;" onclick="return loadmaskloading();" class="btnsubmit" value="Đăng tin" name=""></span>
                    </li>
                </ul>
            }
        </div>

    </div>
    <div class="page_post_news_right">

        @Html.Action("PannelAccount", "Account")

    </div>
    <div class="clear"></div>

</div>

<link href="~/Content/fileuploader.css" rel="stylesheet" />
<link href="@Url.Content("~/Scripts/bbeditor/jquery.sceditor.min.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/bbeditor/jquery.sceditor.min.js")" type="text/javascript"></script>
<link href="~/Scripts/jquery-easyui/themes/metro/easyui.css" rel="stylesheet" />
<script src="~/Scripts/jquery-easyui/jquery.easyui.min.js"></script>
<script src="@Url.Content("~/ckeditor/ckeditor.js")" type="text/javascript"></script>
<link href="~/Scripts/jquery-loadmask/jquery.loadmask.css" rel="stylesheet" />
<script src="~/Scripts/jquery-loadmask/jquery.loadmask.js"></script>
<script src="~/Scripts/fileuploader.js"></script>

<script type="text/javascript">

    function loadmaskloading() {
        $("html, body").animate({ scrollTop: $(window).height()/2 }, "slow");
        $(".formdangtin_news").mask("Dữ liệu đang xử lý...", 500);

    }

    var tinhthanhstr, quanhuyenstr;

    $(function () {

        tinhthanhstr = "";
        quanhuyenstr = "";

        initialize_maps(10.82319, 106.629682);

        CKEDITOR.replace('ck_editor_model', {
            filebrowserBrowseUrl: '/Upload/BrowseImage',
            filebrowserImageUploadUrl: '/Upload/UploadImage',
            height: "350",
            width: "630"
        });

        $(".button_remove_img").attr("disabled", "disabled");

        var thumblogo = $("img#imageslogo");
        var buttonlogo = $("#event-logo-upload")[0];
        var uploader = new qq.FileUploader({
            element: buttonlogo,
            allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
            sizeLimit: 2147483647, // max size
            action: '/Post/UploadImagePost',
            multiple: false,
            onSubmit: function (file, extension) {
                //$('div.preview').addClass('loading');
            },
            onComplete: function (id, fileName, responseJSON) {
                if ($("#AnhDaiDien").val() != "") {
                    deletefileUpload();
                }
                $("#AnhDaiDien").val(responseJSON.filePath);
                thumblogo.attr('src', responseJSON.filePath);
                thumblogo.css('display', 'block');
                $(".button_remove_img").removeAttr("disabled");
            }
        });

        $(".button_remove_img").click(function () {
            deletefileUpload();
        });

        @*$(".Des_on_Maps").sceditorBBCodePlugin({
            style: "@Url.Content("~/Scripts/bbeditor/jquery.sceditor.default.min.css")",
            toolbar: "bold,italic,underline,strike,size,link,unlink,image|bulletlist,orderedlist|code,quote|source|removeformat|youtube",
            resizeMaxHeight: -1,
            width: 630,
            height : 150,
            resizeMinWidth: 630,
            resizeMaxWidth: 630
        });*@

        $("#Des_on_Maps").keyup(function (e) {
            updateInfoWindow($(this).val());

            if ($(this).val() == "" || $(this).val() == null) {
                hideInfoWindow();
            }

        });

        $("#diachi_id").keyup(function (e) {

            var tinh_thanh_id = $("#TinhThanhID").val();
            var quan_huyen_id = $("#QuanhuyenID").val();

            if (tinh_thanh_id == "0") {
                $(".check_qh_tinhthanh").html('Vui lòng chọn tỉnh thành ...');
                $(".check_qh_tinhthanh").show();
                $(".check_qh_tinhthanh").delay(4000).fadeOut(500);
                $(this).val("");
                return false;
            }

            //if (quan_huyen_id == "0") {
            //    $(".check_qh_tinhthanh").html('Vui lòng chọn quận huyện ...');
            //    $(".check_qh_tinhthanh").show();
            //    $(".check_qh_tinhthanh").delay(4000).fadeOut(500);
            //    $(this).val("");
            //    return false;
            //}

            getByAddress( $(this).val() + "," + quanhuyenstr + "," + tinhthanhstr );

        });

        var trees = $('#selectCate').combotree({
            url: '/Post/GetCateHoaDorpList',
            onSelect: function (rec) {
                $("#ParentIdCode").val(rec.id);
            }
        });

        var treestt = $('#selectCate_tt').combotree({
            url: '/Post/GetCateTTDorpList',
            onSelect: function (rec) {
                $("#TinhThanhID").val(rec.id);
                getByAddress(rec.text);
                tinhthanhstr = rec.text;
                quanhuyenstr = "";
                $("#diachi_id").val("");
                var treesqh = $('#selectCate_qh').combotree({
                    url: '/Post/GetCateQHDorpList?tinhthanhiD=' + rec.id,
                    onSelect: function (recs) {
                        $("#QuanhuyenID").val(recs.id);
                        getByAddress($("#diachi_id").val() + "," + recs.text + "," + rec.text);
                        quanhuyenstr = recs.text;
                    }
                });

            }
        });

    });

    function deletefileUpload() {
        $.ajax({
            type: "POST",
            url: "/Post/DeleteFilePost",
            data: { url: $("#AnhDaiDien").val() }
        }).done(function (msg) {
            $("#AnhDaiDien").val("");
            var thumblogo = $("img#imageslogo");
            thumblogo.attr('src', "");
            $(".button_remove_img").attr("disabled", "disabled");
            $(".qq-upload-list").html("");
        });
    }

    function completedAjaxRequest(obj) {
        var returnObj = eval('(' + obj.responseText + ')');
        if (returnObj.Status == "success") {

            var strSplit = returnObj.RedirectUrl.split(",");

            window.location.href = strSplit[0] + "/" + strSplit[1];

        } else {
            makeErrorHighlight(returnObj.Message);
            $(".formdangtin_news").unmask();
        }
        return false;
    }

    function makeErrorHighlight(messageStr) {
        var $highlight = $("<div style='padding: 0.7em; margin-bottom:5px; width: inherit;'><p><span class='' style='float: left;'></span><strong>Lỗi: </strong>" + messageStr + "</p></div>");
        $highlight.addClass("ui-state-highlight ui-corner-all");
        $highlight.prependTo(".warning-area");
        $("html, body").animate({ scrollTop: 100 }, "slow");
        $highlight.delay(4000).fadeOut(500);

    }

</script>